package connect

import (
	"github.com/spf13/viper"
	"punch-in/s/db"
	"punch-in/s/db/mysql"
	"punch-in/s/db/sqlite"
	"time"
)

func Connect() *db.Db {
	var connectDb db.ConnectDb
	useDriver := viper.GetString("useDriver")
	if useDriver == "mysql" {
		connectDb = new(mysql.Mysql)
	} else {
		connectDb = new(sqlite.Sqlite)
	}
	db, err := connectDb.Connect()
	if err != nil {
		panic(err)
	}

	db.Conn.TZLocation, _ = time.LoadLocation("Asia/Shanghai")
	db.Conn.DatabaseTZ, _ = time.LoadLocation("Asia/Shanghai")
	return db
}
